import { Application, BackendSession } from 'pinus';
import { Code } from '../../../consts/code';
import { RecordService } from "../../../services/recordService";

export default function (app: Application) {
    return new GameHandler(app);
}

export class GameHandler {
    private _recordService: RecordService;
    constructor(private app: Application) {
        this._recordService = app.get("recordService")
    }

    /**
     * 查询赔付排行(前20条)
     * @param msg
     * @param session
     * @returns
     */

    public async cashOutRank(msg: {}, session: BackendSession) {
        //获取记录
        const gameRecordInfo = await this._recordService.cashOutRank()
        return { code: Code.OK, data: gameRecordInfo }
    }

    /**
     * 查询最近下注信息(前20条)
     * @param msg
     * @param session
     * @returns
     */

    public async cashOutMines(msg: {}, session: BackendSession) {
        //获取记录
        const gameRecordInfo = await this._recordService.cashOutMines()
        return { code: Code.OK, data: gameRecordInfo }
    }

    /**
     * 查询倍率排行(前20条)
     * @param msg
     * @param session
     * @returns
     */
    public async multipleRank(msg: {}, session: BackendSession) {
        const gameRecordInfo = await this._recordService.multipleRank()
        return { code: Code.OK, data: gameRecordInfo }
    }


    /**
     * 查询用户游戏记录(最近20条)
     * @param msg
     * @param session
     * @returns
     */
    public async userRecord(msg: {}, session: BackendSession) {
        const userId = parseInt(session.uid)
        const gameRecordInfo = await this._recordService.userRecord(userId)
        return { code: Code.OK, data: gameRecordInfo }
    }



}
